/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.z100h.supplychain.evidence.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.z100h.supplychain.evidence.entity.StockoutSku;
import com.z100h.supplychain.evidence.entity.StockoutSkuVo;
import com.z100h.supplychain.evidence.mapper.StockoutSkuMapper;

/**
 * 出库skuService
 * @author madara
 * @version 2019-01-18
 */
@Service
@Transactional(readOnly = true)
public class StockoutSkuService extends CrudService<StockoutSkuMapper, StockoutSku> {

	@Autowired
	private StockoutSkuMapper stockoutSkuMapper;

	@Override
	public StockoutSku get(String id) {
		return super.get(id);
	}

	@Override
	public List<StockoutSku> findList(StockoutSku stockoutSku) {
		return mapper.findList(stockoutSku);
	}

	@Override
	public Page<StockoutSku> findPage(Page<StockoutSku> page, StockoutSku stockoutSku) {
		return super.findPage(page, stockoutSku);
	}

	@Override
	@Transactional(readOnly = false)
	public void save(StockoutSku stockoutSku) {
		super.save(stockoutSku);
	}

	@Override
	@Transactional(readOnly = false)
	public void delete(StockoutSku stockoutSku) {
		super.delete(stockoutSku);
	}

	/**
	 * 根据传入的resid 聚合sku数量
	 * @param stockoutSku
	 * @return
	 */
	public List<StockoutSku> findResourceIdGroupBySkuId(StockoutSku stockoutSku) {
		return stockoutSkuMapper.findResourceIdGroupBySkuId(stockoutSku);
	}

	/**
	 * 根据凭证单号查询所有sku剩余 数量
	 * @param stockoutSku
	 * @return
	 */
	public List<StockoutSku> findSkuAmountOut(StockoutSku stockoutSku) {
		return stockoutSkuMapper.findSkuAmountOut(stockoutSku);
	}

	public List<StockoutSku> findStockoutSkuByEvidenceId(String evidenceId) {
		return stockoutSkuMapper.findStockoutSkuByEvidenceId(evidenceId);
	}

	public List<StockoutSku> findStockoutSkuByOrderIds(List<String> orderIds) {
		return stockoutSkuMapper.findStockoutSkuByOrderIds(orderIds);
	}

	public List<StockoutSku> findStockoutSkuByStockroomId(String stockroomId) {
		return stockoutSkuMapper.findStockoutSkuByStockroomId(stockroomId);
	}

	public List<StockoutSku> findRepairoutSkuByEvidenceId(String evidenceId) {
		return stockoutSkuMapper.findRepairoutSkuByEvidenceId(evidenceId);
	}

	/**
	 * 
	 * 查询未出库的sku
	 * 
	 * @param evidenceId
	 * @return
	 * @author: Fyh - 1009173473@qq.com 
	 * @date: Created on 2019年5月15日 上午9:54:29
	 */
	public List<StockoutSku> findUnStockoutSkuListByEvidenceId(String evidenceId) {
		return stockoutSkuMapper.findUnStockoutSkuListByEvidenceId(evidenceId);
	}

	@Transactional(readOnly = false)
	public void updateStockoutSkuAmountOut(String evidenceId, Integer skuId, Integer amount) {
		stockoutSkuMapper.updateStockoutSkuAmountOut(evidenceId, skuId, amount);
	}

	@Transactional(readOnly = false)
	public void updateStockoutSkuAmountIncrementOut(String evidenceId, Integer skuId, Integer amount) {
		stockoutSkuMapper.updateStockoutSkuAmountIncrementOut(evidenceId, skuId, amount);
	}

	public List<StockoutSkuVo> findSkuNotStockout(String companyId) {
		return stockoutSkuMapper.findSkuNotStockout(companyId);
	}

	public void saveSku(String evidenceId) {
		StockoutSku stockoutSku = new StockoutSku();
		stockoutSku.preInsert();
		stockoutSkuMapper.insertOrderAndRepair(evidenceId, stockoutSku);
	}

	public List<StockoutSku> findSkuByEvidenceIds(List<String> evidenceIds) {
		return stockoutSkuMapper.findSkuByEvidenceIds(evidenceIds);
	}

	public List<String> findUnfinishSkuByEid(String evidenceId) {
		return stockoutSkuMapper.findUnfinishSkuByEid(evidenceId);
	}

}